package com.wikidot.designpatterns.memento;

/**
 * The client application wants to modify state of the originator object.
 * Tracking of changes is desired.
 */
public class Client {
	public static void main(String[] args) {
		HistoryLog history = new HistoryLog();
		Image image = new Image();

		// checkpoint 1: part of the image is made visible
		image.setVisibility(new Dimension(10, 10), true);
		image.display();
		history.saveRecord(image.rememberSettings());

		// checkpoint 2: image is invisible
		image.setVisibility(null, false);
		image.display();
		history.saveRecord(image.rememberSettings());

		// unhide the image again
		image.setVisibility(null, true);
		image.display();

		// resize the visible area
		image.setVisibility(new Dimension(50, 10), true);
		image.display();

		// checkpoint 3: bigger part of the image is made visible
		image.setVisibility(new Dimension(50, 50), true);
		image.display();
		history.saveRecord(image.rememberSettings());

		// look at the saved states
		history.listRecords();

		// return to checkpoint 1: image will be visisble with area of 10x10
		image.restore(history.getRecord(0));
		image.display();
	}
}
